package com.drore.logapp.mvp;

import com.drore.logapp.base.BasePresenter;
import com.drore.logapp.bean.BaseBean;
import com.drore.logapp.bean.LogBean;
import com.drore.logapp.http.token.MySubscriber;
import com.drore.logapp.utils.ToastUtil;


/**
 * desc
 *
 * @author sixbing
 * @date 2018/12/12 9:58
 */

public class AppPresenter extends BasePresenter<AppContract.AppView> {
    private String TAG = AppPresenter.class.getSimpleName();
    private AppModel homeModel;

    public AppPresenter() {
        homeModel = new AppModel();
    }

    public void getLoganList(int page) {
        addSubscription(homeModel.getLoganList(page).subscribe(new MySubscriber<BaseBean<LogBean>>() {
            @Override
            public void onSuccess(BaseBean<LogBean> tResponse) {
                if (tResponse != null) {
                    mView.showLogList(tResponse);
                } else {
                    ToastUtil.show(context, "请求数据失败，请稍后重试");
                }
            }

            @Override
            public void onFailed(String message) {
                mView.showDataError(message);
            }
        }));
    }

    public void loginToken() {
        addSubscription(homeModel.loginToken().subscribe(new MySubscriber<BaseBean<String>>() {
            @Override
            public void onSuccess(BaseBean<String> tResponse) {
                mView.showLogError(tResponse);
            }

            @Override
            public void onFailed(String message) {
                mView.showDataError(message);
            }
        }));
    }

    public void getUserDetail() {
        addSubscription(homeModel.getUserDetail().subscribe(new MySubscriber<BaseBean>() {
            @Override
            public void onSuccess(BaseBean data) {
                mView.showDataSuccess(data);
            }

            @Override
            public void onFailed(String message) {
                mView.showDataError(message);
            }
        }));
    }

    public void getThingDetail() {
        addSubscription(homeModel.getThingDetail().subscribe(new MySubscriber<BaseBean>() {
            @Override
            public void onSuccess(BaseBean data) {
                mView.showDataSuccess(data);
            }

            @Override
            public void onFailed(String message) {
                mView.showDataError(message);
            }
        }));
    }

    public void getTimeOut() {
        addSubscription(homeModel.getTimeOut().subscribe(new MySubscriber<BaseBean>() {
            @Override
            public void onSuccess(BaseBean data) {
                mView.showDataSuccess(data);
            }

            @Override
            public void onFailed(String message) {
                mView.showDataError(message);
            }
        }));
    }
}
